package com.example.demo.config;

import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Admin
 * Date: 2023-03-11
 * Time: 18:23
 */
/*
* 异常的统一处理
* */
@ControllerAdvice
public class ErrorAdive {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public HashMap<String,Object> exceptionAdive(Exception e) {
        HashMap<String,Object> result = new HashMap<>();
        result.put("put","-1");
        result.put("mesg",e.getMessage());
        return result;
    }

    @ExceptionHandler(ArithmeticException.class)
    @ResponseBody
    public HashMap<String,Object> arithmeticExceptionAdive(ArithmeticException e) {
        HashMap<String,Object> result = new HashMap<>();
        result.put("put","-1");
        result.put("mesg",e.getMessage());
        return result;
    }
}
